<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>websocket通信</title>
  </head>
  <body>
    <input type="text" id="text" />
    <input type="button" onclick="sendMessage()" value="online" />
    <script>
      var ws = new WebSocket("ws://localhost:8888");

      ws.onopen = function(e) {
        console.log("Connection to server opened");
        console.log(ws)
      };

      ws.onmessage = function(event) {
        console.log("Client received a message", event);
      };

      ws.onclose = function(e) {
        console.log("connection closed.");
      };
      
      function sendMessage() {
        ws.send(document.getElementById("text").value);
      }
    </script>
  </body>
</html>
